//
//  CZCartoonViewController.m
//  nsj_iOS
//
//  Created by apple on 2017/1/16.
//  Copyright © 2017年 GCZ. All rights reserved.
//

#import "CZCartoonViewController.h"
#import "CZWebNoticeViewController.h"
@interface CZCartoonViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *cartoonImageView;
@property (nonatomic, copy) NSString *articleLink;

@end

@implementation CZCartoonViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self postCartoonData];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cartoonLink)];
    [self.cartoonImageView addGestureRecognizer:tap];
    // Do any additional setup after loading the view from its nib.
}
- (void)cartoonLink {
    
    CZWebNoticeViewController *webVC = [[CZWebNoticeViewController alloc] init];
    webVC.type = @"动漫连载";
    webVC.urlString = self.articleLink;
    [self.parentViewController.navigationController pushViewController:webVC animated:YES];
}

#pragma mark- 获取连载动漫
- (void)postCartoonData {
    NSString *urlString = [NSString stringWithFormat:@"%@/api/web/index.php/v1/article/index",APP_HOST];
    [SVProgressHUD show];
    [GCZAFNetWorking POST:urlString params:@{@"article_type" : @3} success:^(NSDictionary *response) {
        [SVProgressHUD dismiss];
        if ([response[@"code"] isEqualToString:@"200"]) {
            self.cartoonImageView.userInteractionEnabled = YES;
            NSArray *array = response[@"result"];
            NSDictionary *dic = array[0];
            
            self.cartoonImageView.yy_imageURL = [NSURL URLWithString:dic[@"cover_pic"]];
            self.articleLink = dic[@"article_link"];
        }
    } failure:^(NSURLSessionDataTask *operation, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
